#! /usr/bin/python
import sys
import os

cmd = ""
result=""

cmd ="mkdir result"
os.system(cmd)

cmd ="mkdir result/time"
os.system(cmd)

cmd ="mkdir result/event"
os.system(cmd)

cmd ="mkdir result/cpu"
os.system(cmd)

for keySize in [1,3,5,7,9,11,13,15]:
    cmd= "rm -rf sortTable* sortKey"
    os.system(cmd)
    cmd = "./sortBinaryGen 1 1 " + str(keySize)
    os.system(cmd)
    cmd = "chmod 777 sortTable* sortKey"
    os.system(cmd)

    result = "result/time/" + str(keySize) + "_noprof"
    cmd = "./sortTest sortTable  1 1 " + str(keySize) +   " > " + result
    os.system(cmd)
    os.system(cmd)

    result = "result/time/" + str(keySize)
    cmd = "nvprof ./sortTest sortTable  1 " + str(keySize) +   "  > " + result
    os.system(cmd)
    os.system(cmd)

    result = "result/event/" + str(keySize) + "_mem_request" 
    cmd = "nvprof --events gld_request,gst_request ./sortTest sortTable  1 " + str(keySize) +   "  > " + result
    os.system(cmd)

    result = "result/event/" + str(keySize) + "_mem_ld_transaction" 
    cmd = "nvprof --events l1_global_load_hit,l1_global_load_miss ./sortTest sortTable  1 " + str(keySize) +   "  > " + result
    os.system(cmd)

    result = "result/event/" + str(keySize) + "_mem_st_transaction" 
    cmd = "nvprof --events global_store_transaction ./sortTest sortTable  1 " + str(keySize) +   "  > " + result
    os.system(cmd)

    result = "result/event/" + str(keySize) + "_inst" 
    cmd = "nvprof --events inst_issued,inst_executed ./sortTest sortTable 1 " + str(keySize) +   " > " + result
    os.system(cmd)

cmd= "rm -rf sortTable* sortKey"
os.system(cmd)
